package net.zjitc.service.Impl;

import net.zjitc.mapper.OrderMapper;
import net.zjitc.mapper.UserMapper;
import net.zjitc.pojo.Order;
import net.zjitc.pojo.OrderItem;
import net.zjitc.pojo.User;
import net.zjitc.service.OrderService;
import net.zjitc.vo.OrderConditionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author admin
 * @Date 2019/4/9 8:13
 */
@Service
@Transactional
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    UserMapper userMapper;
    @Override
    public List<Order> findAll() {
        return orderMapper.findAll();
    }

    @Override
    public List<Order> findOrderByDate(String year, String month) {
        return orderMapper.findOrderByDate(year,month);
    }

    @Override
    public List<OrderItem> findItemByOrderid(List<Order> orders) {
        return orderMapper.findItemByOrderid(orders);
    }

    @Override
    public Order findById(String id) {
        return orderMapper.findById(id);
    }

    @Override
    public List<Order> findByCondition(OrderConditionVo vo) {
        List<Order> orderList = orderMapper.findByCondition(vo);
        for (Order order :orderList){
            User user = userMapper.findById(order.getUser_id());
            order.setUser(user);
        }
        return orderList;
    }

    @Override
    public void delete(String id) {
        orderMapper.delete(id);
    }

    @Override
    public List<Order> findByDayInInterval(String day) {
        return orderMapper.findByDayInInterval(day);
    }

    @Override
    public int add(Order order) {
        return orderMapper.add(order);
    }

    @Override
    public List<Order> findOrderByUser(int id) {
        return orderMapper.findOrderByUser(id);
    }

    @Override
    public void update_state(String id) {
        orderMapper.update_state(id);
    }


}
